package jtk.project4.fleet.ibatis.dao;

import java.sql.SQLException;
import java.util.List;

import jtk.project4.fleet.domain.Receipts;
import jtk.project4.fleet.domain.Vendor;

public class ReceiptsDao extends IbatisDao{
	
	public List selectAllReceipts() throws SQLException {
		return getSqlMap().queryForList("SELECT_ALL_RECEIPTS", null);
	}
	
	public Receipts selectReceiptById(int id) throws SQLException{
		return (Receipts) getSqlMap().queryForObject("SELECT_RECEIPTS_BY_ID",id);
	}
	
	public int deleteReceipt(Receipts receipt) throws SQLException{
		return (int) getSqlMap().delete("DELETE_RECEIPTS", receipt);
	}
	
	public int updateReceipt(Receipts receipt) throws SQLException{
		return (int) getSqlMap().update("UPDATE_RECEIPTS", receipt);
	}
	
	public Receipts insertReceipts(Receipts receipt) throws SQLException{
		return (Receipts) getSqlMap().insert("INSERT_RECEIPT", receipt);
	}
	
	public static void main(String[] args) throws SQLException{
		//deklarasi objek dan list objek
		Receipts rec = new Receipts();
		List<Receipts> lis ;
		lis = new ReceiptsDao().selectAllReceipts();
		System.out.println(lis.size());
		rec = new ReceiptsDao().selectReceiptById(1);
		System.out.println(rec.getType());
		
		rec.setPartId(99);
		rec.setRecId(999);
		
		new ReceiptsDao().deleteReceipt(rec);
	}	
}